-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Declare tentative return types for ext/spl - part 2 #7235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fe8902b
to
9ef94bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few methods here that should really be void, but I guess we should just go with this.
/** @return int */ | ||
public function key() {} | ||
/** @tentative-return-type */ | ||
public function key(): int {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an application I use, I can easily refactor a current subclass of SplObjectStorage to use composition instead of inheritance https://github.com/phan/phan/blob/v5/src/Phan/Library/Map.php#L30-L40 ( at the cost of a bit of speed) and suppress for now via annotation
But I wonder how many things override SplObjectStorage right now to change key/current to something else in the absense of a native Map
type for objects outside of ds/its polyfill.
Aside: Would it make sense to add a new method SplObjectStorage->currentValue() to avoid the need to call $splObjectStorage->offsetGet($splObjectStorage->current())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I hate the interface that SplObjectStorage exposes (it probably is that way because it predates the non-int/string iterator key support I added in PHP 5.5 or so), your class still clearly violates the API -- if something accepts an SplObjectStorage and is passed your Map instead, it will not behave correctly. So I do think that switching the implementation to use composition would be the right move here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, It turns out the functionality I was thinking of already exists as https://www.php.net/manual/en/splobjectstorage.getinfo.php
No description provided.